﻿Imports Negocio
Imports Servicios
Imports Excepciones

Public Class frmConsultaIdioma

    Protected Overrides Sub PreLoad()
        Me.Icon = Icon.FromHandle(Global.SIPRO.My.Resources.Resources.Language.GetHicon())
    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        Dim i As Idioma = Current.Idioma.Clonar()
        Dim f As New frmABMIdioma(i)
        If f.ShowDialog = DialogResult.OK Then
            Init()
        End If
    End Sub

    Private Sub frmConsultaIdioma_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Init()
    End Sub

    Private Sub Init()
        Try

            Dim idis As List(Of Idioma) = GesIdiomas.Consultar(Nothing)
            lbIdiomas.DataSource = idis
            lbIdiomas.ValueMember = "OID"
            lbIdiomas.DisplayMember = "Nombre"
        Catch ex As Exception
            My.Application.HandlerException(ex)
            Me.Close()
        End Try
    End Sub

    Private Sub btnEliminar_Click(sender As System.Object, e As System.EventArgs) Handles btnEliminar.Click

        If lbIdiomas.Items.Count > 0 AndAlso TypeOf lbIdiomas.SelectedItem Is Idioma Then
            If MessageExt.Show(GesIdiomas.TraduceMensaje("MSGI001").ToString, MessageBoxButtons.OKCancel) = DialogResult.OK Then
                Dim idi As New Idioma()
                idi = DirectCast(lbIdiomas.SelectedItem, Idioma)
                Try
                    GesIdiomas.Eliminar(idi)
                Catch ex As Exception
                    My.Application.HandlerException(ex)
                End Try
                Init()
            End If
        Else
            My.Application.HandlerException(New ItemSelectRequiredException())
        End If

    End Sub

    Private Sub Cancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCerrar.Click
        Me.Close()
    End Sub

    Private Sub lbIdiomas_DoubleClick(sender As System.Object, e As System.EventArgs) Handles lbIdiomas.DoubleClick

        If lbIdiomas.Items.Count > 0 AndAlso TypeOf lbIdiomas.SelectedItem Is Idioma Then
            Dim f As New frmABMIdioma(DirectCast(lbIdiomas.SelectedItem, Idioma))
            If f.ShowDialog = DialogResult.OK Then
                Init()
            End If
        Else
            My.Application.HandlerException(New ItemSelectRequiredException())
        End If

    End Sub
End Class